<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- div#app>input -->
    <div id="app">
        <input v-model="item" type="text" @keyup.enter="addItem" />
        <button @click="addItem">按钮添加</button>
        <div v-if="items.length==0">
            食堂里暂时没有菜了
        </div>
        <!-- v-if尽量不和v-for嵌套使用 -->
        <div v-else>
            <p v-for="name in items">
                {{ name }}
            </p>
        </div>
    </div>
    <script src="../assets/vue2.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data() {
                return {
                    item: '', // 变量要定义一下
                    items: ["狮子头", "韭菜", "鸡腿"]
                }
            },
            methods: {
                addItem() {
                    if (this.item == '') { return; }
                    this.items.push(this.item); // 数组中加一个值
                    this.item = ''; // 清空文本框内容
                }
            },
        })
    </script>
</body>

</html>